#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @Time    : 2019/11/24 20:22
# @Author  : linjinting
# @Site    : 
# @Software: PW4Adatatool
# @File    : usergeneration.py
# @Function:

from mysql_model.handle_base import HandleBase
import uuid
import json
from datetime import datetime

SHA512_PASSWORD = "4dff4ea340f0a823f15d3f4f01ab62eae0e5da579ccb851f8db9dfe84c58b2b37b89903a740e1ee172da793a6e79d560e5f7f9bd058a12a280433ed6fa46510a"


class User4A(HandleBase):
    def __init__(self, config_=None):
        super().__init__(config_)
        # self.m_stationList = list()
        self.m_tableName = "t_user4a"

        self.userDatas = None
        self.user4a_data_list = list()
        ###public
        self.userID = None
        self.userDatas = None
        self.loginName = None
        self.realName = None
        # self.lockDataTime = "0000-00-00 00:00:00"
        self.isChangePwd = 1
        self.pwdChangeTime = "0000-00-00 00:00:00"
        # self.errorCount = "0"
        # self.fingerPrintVer = ""
        self.userStatus = 1
        # self.isLogined = "0"
        self.bizOrgId = None
        ###user4a_data
        self.dutyRoles = ""
        ### userDatas
        self.baseOrgName = None
        self.dutyRoles_obj = ""
        self.resZoneName = ""
        self.roleName = ""

    def set_data(self, loginName, realName, bizOrgId, baseOrgName, userID=None, dutyRoles="", resZoneName="", roleName=""):
        """
        :param userID: 必填如果为空调用自动生成id函数
        :param loginName: 登录名
        :param realName: 显示名
        :param bizOrgId: 部门id
        :param baseOrgName :部门名称
        :param dutyRoles: 岗位列表
        :param resZoneName: 资源范围
        :param roleName: 角色
        :return:
        """

        if userID is None:
            uid_ = str(uuid.uuid4())
            self.userID = ''.join(uid_.split('-'))
        else:
            self.userID = userID

        self.loginName = loginName
        self.realName = realName
        self.bizOrgId = bizOrgId
        self.baseOrgName = baseOrgName
        self.pwdChangeTime = datetime.now()
        if dutyRoles is not None:
            self.dutyRoles = dutyRoles
            self.dutyRoles_obj = self.get_dutyRoles_obj(self.dutyRoles)

        self.resZoneName = resZoneName
        self.roleName = roleName

    def get_user4a_field(self):
        return ['userID', 'userDatas', 'loginName', 'realName', 'isChangePwd', 'pwdChangeTime', 'userStatus', 'bizOrgId', 'dutyRoles']


    def get_user4a_value(self):
        self.__userdatas_generation()
        return self.userID, self.userDatas, self.loginName, self.realName, self.isChangePwd, self.pwdChangeTime, self.userStatus, self.bizOrgId, self.dutyRoles

    def __userdatas_generation(self):
        attAccount = ""
        baseOrgId = ""
        duty = ""
        faceCheckPicName = ""
        faceCheckState = ""
        facePicName = ""
        job = ""
        password = SHA512_PASSWORD #固定密码 1
        positionName = ""
        signPicName = ""

        userDatas = {
            'attAccount': attAccount,
            'baseOrgId': baseOrgId,
            'baseOrgName': self.baseOrgName,
            'bizOrgId': self.bizOrgId,
            'duty': duty,
            'dutyRoles': self.dutyRoles_obj,
            'faceCheckPicName': faceCheckPicName,
            'faceCheckState': faceCheckState,
            'facePicName': facePicName,
            'job': job,
            'loginName': self.loginName,
            'password': password,
            'positionName': positionName,
            'realName': self.realName,
            'resZoneName': self.resZoneName,
            'roleName': self.roleName,
            'signPicName': signPicName,
            'userId': self.userID,
            'userStatus': self.userStatus

        }
        self.userDatas = json.dumps(userDatas, indent=0)

    def get_dutyRoles_obj(self, dutyRoles):
        roles = dutyRoles.split(',')
        dutyRoles_list = list()
        for role in roles:
            name = {"dutyRolesName": role}
            dutyRoles_list.append(name)
        return {'dutyRoles': dutyRoles_list}

        # return json.dumps(dutyRoles_json)

    def insert_user_data(self, valueList):
        # tableName = "t_station"
        fields_ = self.get_user4a_field()
        return self.insert_multiple_data(fields_, valueList)


if __name__ == '__main__':
    ug = User4A()
    ug.set_data("alid", "大师傅", "adfa123232313", "嗷嗷待食返回", "00001")
    print(ug.get_user4a_value())
